package org.example.groupwarehouse.mapper;

import org.apache.ibatis.annotations.*;
import org.example.groupwarehouse.entity.Admin;
import org.example.groupwarehouse.entity.Users;
import java.util.List;

@Mapper
public interface AdminMapper {

    long count();

    Admin getAdminByAccount(String account);

    int insertAdmin(Admin admin);

    @Update("UPDATE wn_manager SET status = #{status} WHERE id = #{id}")
    int updateAdminStatus(@Param("id") Integer id, @Param("status") Integer status);


    List<Admin> getAllAdmins();


    List<Users> getAllUsers();
//修改管理员密码。
    @Update("UPDATE wn_manager SET password = #{newPassword} WHERE id = #{id}")
    int updateAdminPassword(@Param("id") Integer id, @Param("newPassword") String newPassword);

    @Select("SELECT * FROM wn_manager WHERE id = #{id}")
    Admin getAdminById(Integer id);

    @Update({
            "<script>",
            "UPDATE wn_manager SET status = #{status} WHERE id IN",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    //批量更新管理员状态（动态 SQL）。
    int batchUpdateStatus(@Param("ids") List<Integer> ids, @Param("status") Integer status);

    @Update({
            "<script>",
            "UPDATE wn_user SET status = '4' WHERE id IN",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    //批量删除用户（实际是更新状态为 4“黑名单”状态）
    int batchDelete(@Param("ids") List<Integer> ids);
//查询指定账号（排除某个 ID）的管理员，用于检测账号重复。
    @Select("SELECT * FROM wn_manager WHERE account = #{account} AND id != #{excludeId}")
    Admin getAdminByAccountExcludeId(@Param("account") String account,
                                     @Param("excludeId") Integer excludeId);

    List<Users> searchUsers(@Param("account")String account,
                            @Param("email")String email,
                            @Param("telephone")String telephone);

    @Update("update wn_user set status ='4' where id = #{id} ")
    void batchDeleteByid(@Param("id") Integer id);
}